/**
  ******************************************************************************
  * @file    APP_TIMER.c 
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   Display interface
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/**
  * @brief  INCLUDE FILES.
  */
#ifndef	APP_TIMER_GLOBALS
#define	APP_TIMER_GLOBALS
#include <includes.h>

uint8_t   TimeDownResetNum=0x00;    

    
/**
  * @brief  Timer01hz
  * @param  none
  * @return none.
  */
void App_Tmr_TIMER01HZCallback (OS_TMR *ptmr, void *p_arg)
{   
	(void)p_arg;
	
	if(ptmr==App_Tmr_TIMER01HZ)
	{			
    /* Update RTC Counter */
    UpdateRTCClockCount();
    /* Maintenance Handle */
    //MaintenanceWorkLoadHandle();
    /* Schedule Start Handle */
    ScheduleStartWorkLoadHandle();

/**************************/
/* Encrypt */
/**************************/

  /* Encrypt Checking Level2 */
  #ifdef EnableMCUEncryptOpt	
  	EncryptCheckTiCnt0++;
  	if(EncryptCheckTiCnt0>=20)
  	{
  		EncryptCheckTiCnt0=0;
  	  CMPLevel2STM32IDArea0();                      /* MCU Running period <70us */
  	}
  #endif 

    /* Read ID */
  #ifdef EnableMCUEncryptOpt
    Read03stSTM32MCUID();
  #endif
  }
}


/**
  * @brief  Timer10hz
  * @param  none
  * @return none.
  */
void App_Tmr_TIMER10HZCallback (OS_TMR *ptmr, void *p_arg)
{
	(void)p_arg;
	
	if(ptmr==App_Tmr_TIMER10HZ)
	{
    /* Fixed Timing to LCD */
    SetOSFlagsForNewInform(App_Flags_HCI,OSHCIFlags_LCDTiming);

		/* Fixed Timing to Scan Digital Inputs */
    SetOSFlagsForNewInform(App_Flags_DSTIN,OSDSTINFlags_DSTINTIMING|OSDSTINFlags_SpeedTiming);
    
    /* Fixed Timing to Measure Normal AD */
    SetOSFlagsForNewInform(App_Flags_NORMAD,OSNORMADFlags_TIMING|OSNORMADFlags_Measure);
    
    /* Fixed Timing to Measure AC AD */
    SetOSFlagsForNewInform(App_Flags_ACAD,OSACADFlags_TIMING);
    
    /* Fixed Timing to Workflow */
    SetOSFlagsForNewInform(App_Flags_WORKFLOW,OSWORKFLOWFlags_SelfTiming);
    
    /* Fixed Timing to RelayOut */
    SetOSFlagsForNewInform(App_Flags_RELAY,OSRelayFlags_UpdTiming);
    
    /* Fixed Timing to WIFI */
    SetOSFlagsForNewInform(App_Flags_NETWORK,OSNETWORKFlags_Timing);    

    /* Fixed Timing to Communi */
    SetOSFlagsForNewInform(App_Flags_COMMUNI,OSCOMMFlags_UpdTiming);
    
    /* Loading Timing handling */
    LoadingPulseTimerHandle();
  }
}


/**
  * @brief  Timer20hz
  * @param  none
  * @return none.
  */
void App_Tmr_TIMER20HZCallback (OS_TMR *ptmr, void *p_arg)
{
	
	(void)p_arg;
	
	if(ptmr==App_Tmr_TIMER20HZ)
	{
    /* Fixed Timing to KeyScan */
    SetOSFlagsForNewInform(App_Flags_HCI,OSHCIFlags_ButtonTiming);
    
    /* Fixed Timing to WIFI */
    SetOSFlagsForNewInform(App_Flags_NETWORK,OSNETWORKFlags_Scand);    

    /* Fixed Timing to LED */
    if(LEDTimingCounter<2)
      LEDTimingCounter++;
    else
    	LEDTimingCounter=0;
    
    if(LEDTimingCounter==0)
      SetOSFlagsForNewInform(App_Flags_HCI,OSHCIFlags_LEDTiming1);
    else if(LEDTimingCounter==1)
      SetOSFlagsForNewInform(App_Flags_HCI,OSHCIFlags_LEDTiming2);
    else
      SetOSFlagsForNewInform(App_Flags_HCI,OSHCIFlags_LEDTiming3);
  }
 
 
}



/*$PAGE*/#endif	/*	APP_TIMER_GLOBALS	*/
